package edu.nctu.csie.jichang.dp.behavioral;

import java.util.Vector;

public class Observer {
	public static void main(String[] args) {
		Publish tPublish = new Publish();
		tPublish.subscribes.add(new SubscribeA());
		tPublish.subscribes.add(new SubscribeB());
		tPublish.setName("abc");
		tPublish.setName("def");
	}
}
class Publish{
	String name;
	Vector<Subscribe> subscribes = new Vector<Subscribe>();
	public void setName(String name) {
		this.name = name;
		for (Subscribe s : subscribes) {
			s.update(this);
		}
	}
}
interface Subscribe{
	public void update(Publish p);
}
class SubscribeA implements Subscribe{
	public void update(Publish p) {System.out.println("A receive p change="+p.name);}
}
class SubscribeB implements Subscribe{
	public void update(Publish p) {System.out.println("B receive p change="+p.name);}
}